<template>
  <div>
    <TodoHeader @add-todo="faAdd" />
    <TodoMain :arr="showList" @delMain="delFn" />
    <TodoFooter
      v-show="list.length > 0"
      :footArr="list"
      @switch-todo="babaSwitch"
    />
  </div>
</template>

<script>
import "./assets/css/base.css";
import "./assets/css/index.css";
import TodoHeader from "./components/TodoHeader";
import TodoMain from "./components/TodoMain";
import TodoFooter from "./components/TodoFooter";

export default {
  components: {
    TodoHeader,
    TodoMain,
    TodoFooter,
  },
  data() {
    return {
      babaType: "all",
      list: [
        { id: 100, name: "吃饭", isDone: true },
        { id: 201, name: "睡觉", isDone: false },
        { id: 103, name: "打豆豆", isDone: true },
      ],
    };
  },
  methods: {
    faAdd(name) {
      //console.log(name);
      const obj = {
        id: Date.now(),
        name,
        isDone: false,
      };
      this.list.push(obj);
    },
    delFn(index) {
      this.list.splice(index, 1);
    },
    babaSwitch(Switchtype) {
      this.babaType = Switchtype;
      //console.log(this.babaType);
    },
  },
  computed: {
    showList() {
      if (this.babaType === "all") {
        console.log(1);
        return this.list;
      } else if (this.babaType === "no") {
        return this.list.filter((item) => item.isDone === false);
      } else {
        return this.list.filter((item) => item.isDone === true);
      }
    },
  },
};
</script>

<style>
</style>